/**
 * Anderground project - Subway maps processor application.
 * Copyright (C) 2008-2009 Eldar Abusalimov, Ilya Shurigyn
 * 
 * This file is part of Anderground.
 * 
 * Anderground is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * Anderground is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Anderground.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.anderground.modules.storage.serial;

import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;

import org.anderground.core.model.ModelData;
import org.anderground.core.storage.ModelReader;
import org.anderground.core.storage.ModelWriter;

/**
 * @author Eldar Abusalimov
 */
public class SerialModelStorage {

	/**
	 * Creates a new {@link ModelReader} that uses the specified {@link File}
	 * for the future reading.
	 * 
	 * @param file
	 *            the file to read from
	 * 
	 * @return {@link ModelReader} implementation instance
	 */
	public static ModelReader createReader(File file) {
		return new SerialModelReader(file);
	}

	/**
	 * Constructs a new {@link ModelReader} that uses a {@link File} created by
	 * converting the specified path string.
	 * 
	 * @param path
	 *            the path of a file to read a data from
	 * 
	 * @return {@link ModelReader} implementation instance
	 */
	public static ModelReader createReader(String path) {
		return new SerialModelReader(path);
	}

	/**
	 * Creates a new {@link ModelReader} that uses the specified
	 * {@link InputStream} for the future reading.
	 * 
	 * @param inputStream
	 *            the stream to read from
	 * @param closeAfterRead
	 *            defines whether to close the stream after
	 *            {@link ModelReader#read()} completes
	 * 
	 * @return {@link ModelReader} implementation instance
	 */
	public static ModelReader createReader(InputStream inputStream,
			boolean closeAfterRead) {
		return new SerialModelReader(inputStream, closeAfterRead);
	}

	/**
	 * Creates a new {@link ModelWriter} instance that uses the specified
	 * {@link File} for the future writing.
	 * 
	 * @param file
	 *            the file to write to
	 * 
	 * @return {@link ModelWriter} implementation instance
	 */
	public static ModelWriter createWriter(File file) {
		return new SerialModelWriter(file);
	}

	/**
	 * Constructs a new {@link ModelWriter} that uses a {@link File} created by
	 * converting the specified path string.
	 * 
	 * @param path
	 *            the path of a file to write a data to
	 * 
	 * @return {@link ModelWriter} implementation instance
	 */
	public static ModelWriter createWriter(String path) {
		return new SerialModelWriter(path);
	}

	/**
	 * Creates a new {@link ModelWriter} instance that uses the specified
	 * {@link OutputStream} for the future writing.
	 * 
	 * @param outputStream
	 *            the stream to write to
	 * @param closeAfterWrite
	 *            defines whether to close the stream after
	 *            {@link ModelWriter#write(ModelData)} completes
	 * 
	 * @return {@link ModelWriter} implementation instance
	 */
	public static ModelWriter createWriter(OutputStream outputStream,
			boolean closeAfterWrite) {
		return new SerialModelWriter(outputStream, closeAfterWrite);
	}

}
